// pages/mine/mine.js
var util = require('../../utils/util');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mineList:[
        {
            icon:'/resources/record-mine.png',
            text:'订餐记录',
            link:'/pages/mineRecord/mineRecord',
            is_manager: false,
            roles: ['0', '1', '2']
        },
        {
          icon:'/resources/record-mine.png',
          text:'新锐订单',
          link:'/pages/myOrder/myOrder',
          is_manager: false,
          roles: ['0', '1', '2']
        },
        {
            icon:'/resources/manage.png',
            text:'订餐管理',
            link:'/pages/managePage/managePage?type=0',
            roles:['1', '2'],
            is_manager: false
        },
        {
          icon:'/resources/manage.png',
          text:'新锐特供管理',
          link:'/pages/payManage/payMange?type=0',
          roles:['1', '2'],
          is_manager: false
        },
        {
          icon:'/resources/admin.png',
          text:'管理后台',
          link:'/pages/admin/admin',
          roles: ['2'],
          is_manager: false
        }
    ]
  },
  //页面跳转
    toPage(e){
       var _this = this;
       var index = e.currentTarget.dataset.index;
        wx.navigateTo({
            url:_this.data.mineList[index].link
        })
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
        util.setNavBarTitle('个人中心');
       
  },
    isManager(){
      var _this = this;
      //   if(app.globalData.isManager != 1){
      //       var mineList = _this.data.mineList;
      //       mineList[1].is_manager = false
      //       _this.setData({
      //           mineList:mineList
      //       })
      //   }
      const manager = app.globalData.isManager;
      const mineList = _this.data.mineList;
      for(let i in mineList) {
        if(mineList[i].roles.indexOf(manager)>= 0) {
          console.log(mineList[i])
          mineList[i].is_manager = true
        }
      }
      _this.setData({
        mineList: mineList
      })
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.isManager(); 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
